<template>
	<view class="chicken_box">
		<u-icon name="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/9fc5f721d07945e5a6c3d1aad1e2f8ae.png"
			label="微信支付" space="50rpx" labelPos="bottom" width="180rpx" height="150rpx" labelSize="32rpx"
			labelColor="#333" />
	</view>
</template>

<script>
	import {
		chickenPay
	} from "@/api/order.js";
	import {
		salesmanChickenPay
	} from "@/api/orderSalesman.js";
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				orderNum: ''
			};
		},
		onLoad(options) {
			this.orderNum = options.trade_no
			console.log(options, 'webpay参数options')
			if (this.$store.getters?.authority === "salesman") {
				this.salesmanPay()
			} else {
				this.pay();
			}
		},
		methods: {
			async salesmanPay() {
				const {
					data
				} = await salesmanChickenPay({
					chickenOrderNum: this.orderNum,
					appId: this.$appId
				});
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: data.timeStamp,
					nonceStr: data.nonceStr,
					package: data.packageValue,
					signType: "MD5",
					paySign: data.paySign,
					success: function(res) {
						if (res.errMsg === "requestPayment:ok") {
							uni.navigateBack({
								delta: 1
							});
						}
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
						uni.navigateBack({
							delta: 1
						});
					},
				});
			},
			async pay() {
				const {
					data
				} = await chickenPay({
					chickenOrderNum: this.orderNum,
					appId: this.$appId
				});
				uni.requestPayment({
					provider: "wxpay",
					timeStamp: data.timeStamp,
					nonceStr: data.nonceStr,
					package: data.packageValue,
					signType: "MD5",
					paySign: data.paySign,
					success: function(res) {
						if (res.errMsg === "requestPayment:ok") {
							uni.navigateBack({
								delta: 1
							});
						}
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
						uni.navigateBack({
							delta: 1
						});
					},
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.chicken_box {
		height: 100vh;
		background-color: #fff;
		margin: 0 auto;
		padding: 300rpx 0 0;
		text-align: center;
	}
</style>
